package com.runrunfast.fxj.utils;

import com.google.common.base.Splitter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/** 级别工具类
 * @author: 陈胤训
 * @create: 2018-12-07 17:31
 **/
public class LevelUtil {

    public final static String SEPARATOR = ":";

    public final static String ROOT = "sys";

    /** 计算级别
     *  0
     *  0.1
     *  0.1.2
     *  0.4
     * */
    public static String  calculateLevel(String parentLevel,Integer parentId){
        if (StringUtils.isBlank(parentLevel)){
            return ROOT;
        }else {
            return StringUtils.join(parentLevel,SEPARATOR,parentId);
        }

    }

    /** 计算级别
     *  0
     *  0.1
     *  0.1.2
     *  0.4
     * */
    public static String  calculateLevel(String parentLevel,String permission){
        if (StringUtils.isBlank(parentLevel)){
            return ROOT;
        }else {
            return StringUtils.join(parentLevel,SEPARATOR,permission);
        }

    }

    /**
     * 把1,2,3,4,5 转为list
     * @param str
     * @return
     */
    public static List<Integer> splitToListInt(String str){
        // 1,2,3,4,5 转为list
        List<String> strings = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(str);
        List<Integer> collect = strings.stream().map(strItem -> Integer.parseInt(strItem)).collect(Collectors.toList());
        return  collect;
    }

    public static void main(String[] args) {
        String a = "1,2,3,4,5";
        String[] split = a.split(",");
        List<String> strings = Arrays.asList(split);
        System.out.println(calculateLevel("11",13));
        if(0>0){
            System.out.println("1");
        }else{
            System.out.println("2");
        }
    }

}
